package com.alex.utils.html;


public class HtmlUtils {

	public static String makeLink(String url, String linkText) {
		return "<a href=\"" + url + "\">" + linkText + "</a>";
	}
	
	public static String removeHtml(String text) {
		StringBuilder res = new StringBuilder(text.length());
		int p1 = 0, p2 = 0, p3 = 0;
		while (true) {
			p1 = text.indexOf('<', p2);
			if (p1 < 0) break;
			p2 = text.indexOf('>', p1);
			if (p2 < 0) break;
			res.append(text.substring(p3, p1));
			p3 = p2 + 1;
		}
		res.append(text.substring(p3));
		
		return res.toString();
	}

	public static String removeLinks(String text) {
		while (true) {
			int p1 = text.indexOf("</a>");
			if (p1 < 0)
				break;
			int p2 = text.lastIndexOf("<a", p1 - 4);
			if (p2 < 0)
				break;
			text = text.substring(0, p2) + text.substring(p1 + 4);
		}
		return text;
	}
}
